package com.xiaoyu.tool.service.kefu;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpKefuService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CustomerService {

    private final WxMpKefuService wxMpKefuService;

    public CustomerService(WxMpKefuService wxMpKefuService) {
        this.wxMpKefuService = wxMpKefuService;
    }


    public String createSession(WxMpXmlMessage wxMpXmlMessage) throws WxErrorException {
        String account = wxMpKefuService.kfList().getKfList().get(0).getAccount();
        log.info("建立客服连接account:{}",account);
        wxMpKefuService.kfSessionCreate(wxMpXmlMessage.getFromUser(),account);
        wxMpKefuService.kfSessionGetWaitCase();
        return "请稍后";
    }

    public void closeSession(WxMpXmlMessage wxMessage) throws WxErrorException {
        String account = wxMpKefuService.kfList().getKfList().get(0).getAccount();
        log.info("关闭客服连接account:{}",account);
        wxMpKefuService.kfSessionClose(wxMessage.getFromUser(),account);
    }
}
